Skip to content

Enable clippy::clone_on_ref_ptr lint and fix all violations#7262

Merged
joseph-isaacs merged 1 commit intodevelopfrom
ji/lint-clone-on-ref-ptr
Apr 8, 2026
Merged

Enable clippy::clone_on_ref_ptr lint and fix all violations#7262
joseph-isaacs merged 1 commit intodevelopfrom
ji/lint-clone-on-ref-ptr

Conversation

@joseph-isaacs
Copy link
Copy Markdown
Contributor

@joseph-isaacs joseph-isaacs commented Apr 2, 2026

Summary

  • Adds clone_on_ref_ptr = "deny" to [workspace.lints.clippy] in the root Cargo.toml
  • Fixes all ~450 violations across 126 files by replacing x.clone() on Arc/Rc/Weak with explicit Arc::clone(&x) (or turbofish Arc::<T>::clone(&x) where type coercion is needed)
  • No #[allow] suppressions anywhere

@joseph-isaacs joseph-isaacs changed the title wip see what Arc::clone looks like Apr 2, 2026
@joseph-isaacs joseph-isaacs changed the title see what Arc::clone looks like chore: use Arc::clone over x.clone where x is an Arc Apr 8, 2026
@joseph-isaacs joseph-isaacs marked this pull request as ready for review April 8, 2026 09:59
@0ax1 0ax1 self-requested a review April 8, 2026 10:04
@0ax1
Copy link
Copy Markdown
Contributor

0ax1 commented Apr 8, 2026

@claude search if any bug sneaked into this pr

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 8, 2026

Claude finished @0ax1's task in 10m 34s —— View job


Bug Hunt: Arc::clone PR Review

  • Gather context and read the diff
  • Analyze each changed file for bugs
  • Report findings

Summary

I reviewed the full diff (~1,059 Arc::clone substitutions across 100 files) looking for bugs that may have sneaked in during this mechanical refactoring. No bugs were found.

Here's what I verified:

Correctness of conversions

Every .clone() that was converted to Arc::clone() was confirmed to be on an Arc-backed type:

  • ArrayRef = Arc<dyn DynArray> — the vast majority of conversions (returned by indices(), values(), ends(), elements(), offsets(), sizes(), encoded(), etc., which all return &ArrayRef)
  • Arc<DType> — matched via DType::List(element_dtype, ..) / DType::FixedSizeList(element_dtype, ..) variants
  • Arc<[ArrayRef]> / Arc<[BufferHandle]> — from unmasked_fields() / buffers()
  • LayoutRef = Arc<dyn Layout> — layout handling in vortex-file
  • Arc<[SegmentSpec]> — segment map handling

Non-Arc clones correctly left alone

Types that are NOT ref-counted were correctly not converted: Mask, DType (the enum itself), Option<ArrayRef> (the Option wrapper), Exponents, FSSTArray (concrete struct), etc.

Method chaining is safe

Patterns like Arc::clone(patches.indices()).execute::<PrimitiveArray>(ctx)? are semantically identical to patches.indices().clone().execute::<PrimitiveArray>(ctx)?. Both produce an Arc<dyn DynArray> which auto-derefs for the .execute() call.

as _ coercion casts

In benchmarks/datafusion-bench/src/lib.rs and a strategy test, as _ was added alongside Arc::clone. This is correct and necessary: .clone() on Arc<ConcreteType> would implicitly coerce to Arc<dyn Trait>, but Arc::clone returns the concrete type, requiring an explicit as _ cast. No semantic change.

Consistency of Option handling

chunk_offsets() returns &Option<ArrayRef> and its .clone() was correctly left as-is (since Option is not itself an Arc). When pattern-matched as let Some(chunk_offsets) = patches.chunk_offsets(), the inner &ArrayRef is correctly used with Arc::clone.


Verdict: ✅ No bugs found

This is a clean, mechanically consistent lint-compliance refactoring. The clone_on_ref_ptr = "deny" clippy lint added to Cargo.toml will catch any future violations.

Copy link
Copy Markdown
Contributor

@AdamGS AdamGS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes please

@joseph-isaacs joseph-isaacs changed the title chore: use Arc::clone over x.clone where x is an Arc Enable clippy::clone_on_ref_ptr lint and fix all violations Apr 8, 2026
Adds `clone_on_ref_ptr = "deny"` to workspace clippy lints, enforcing
explicit `Arc::clone(&x)` instead of `x.clone()` on ref-counted pointers
to make refcount bumps visually distinct from deep clones.

Signed-off-by: Joseph Isaacs <joseph@spiraldb.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@joseph-isaacs joseph-isaacs force-pushed the ji/lint-clone-on-ref-ptr branch from 136811f to 80a2419 Compare April 8, 2026 14:17
@joseph-isaacs joseph-isaacs enabled auto-merge (squash) April 8, 2026 14:51
@joseph-isaacs joseph-isaacs added the changelog/chore A trivial change label Apr 8, 2026
@joseph-isaacs joseph-isaacs merged commit d72bf9b into develop Apr 8, 2026
64 of 65 checks passed
@joseph-isaacs joseph-isaacs deleted the ji/lint-clone-on-ref-ptr branch April 8, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/chore A trivial change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants